package com.yaoli.hihocoder;

import java.util.Scanner;

/**
 * Created by will on 2017/4/8.
 */
public class _DiligentRobots {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int q = input.nextInt();

        int hour = Integer.MAX_VALUE;

        boolean flag = true;

        int robot = 1;

        int num = 1;

        while(flag == true){
            if(n / robot < hour){
                hour = n/robot;
            }

            robot = robot << 1;
            num ++ ;
            int tempHour = q * num + n / robot;
            if(tempHour < hour){
                hour = tempHour;
                continue;
            }else {
                break;
            }
        }
        System.out.print(hour);
    }
}
